/**
 * Controller
 * @version 1.0
 * Copyright: Wolna licencja
 */
package pl.put.io.code.core;

import java.io.IOException;
import java.util.List;

import pl.put.io.code.input.DataReader;
import pl.put.io.code.input.FileDataReader;

/**
 * <p>
 * Klasa generująca zdania na podstawie zawartości wczytywanych plików
 * tekstowych .
 * </p>
 * 
 */

public class Controller {

    public static final String NAMES_FILE_NAME = "names.txt";
    public static final String ACTIVITIES_FILE_NAME = "activities.txt";
    public static final String PLACES_FILE_NAME = "places.txt";

    private DataReader namesDataReader;
    private DataReader activitiesDataReader;
    private DataReader placesDataReader;

    /**
     * otwiera pliki do odczytu
     */
    public Controller() {
	namesDataReader = new FileDataReader(NAMES_FILE_NAME);
	activitiesDataReader = new FileDataReader(ACTIVITIES_FILE_NAME);
	placesDataReader = new FileDataReader(PLACES_FILE_NAME);
    }

    /**
     * 
     * wykonuje metodę {@link SenteceCreator#createSentences(int) } tworzącą
     * zdania oraz {@link Controller#printSentences(List)} wypisującą zdania
     * 
     * @param numberOfSentences
     *            liczba zdań do wygenerowania
     * @throws IOException
     */
    public void generateSentences(int numberOfSentences) throws IOException {
	SenteceCreator creator = new SenteceCreator(
		namesDataReader.readInput(), activitiesDataReader.readInput(),
		placesDataReader.readInput());
	final List<String> sentences = creator
		.createSentences(numberOfSentences);
	printSentences(sentences);
    }

    /**
     * wypisuje zdania
     * 
     * @param sentences
     *            lista zdań do wypisania
     */
    private void printSentences(List<String> sentences) {
	for (String sentence : sentences) {
	    System.out.println(sentence);
	}

    }

}
